//1. 和为k的子数组;

class Solution 
{
public:
    int subarraySum(vector<int>& nums, int k) 
    {
        //映射sum和出现次数;
        unordered_map<int, int> hash;
        hash[0] = 1;

        int sum = 0, ret = 0;
        for(int i = 0; i < nums.size(); i++)
        {
            //先进行加和, 然后判断前面和-k是否
            sum += nums[i];
            if(hash.count(sum - k))
            {
                ret += hash[sum - k];
            }
            hash[sum]++;
        }

        return ret;
    }
};